﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Stl.Chat.Services.Plugin
{
    public partial class GeneratorConfigDialog : Form
    {
        public static int DefaultInterval { get { return 500; } }
        public static string DefaultMessage { get { return "Generated message"; } }
        public static ChatMsgGenerator.GeneratorType DefaultMode
        {
            get { return ChatMsgGenerator.GeneratorType.Timer; }
        }

        public int Interval
        {
            get;
            protected set;
        }

        public string Message
        {
            get;
            protected set;
        }

        public ChatMsgGenerator.GeneratorType Mode
        {
            get;
            protected set;
        }

        public GeneratorConfigDialog(int interval, string message, ChatMsgGenerator.GeneratorType mode)
        {
            InitializeComponent();

            intervalTextBox.Text = interval.ToString();
            messageTextBox.Text = message;
            if (mode == ChatMsgGenerator.GeneratorType.Thread)
                threadRadioButton.Checked = true;
            else
                timerRadioButton.Checked = true;
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            string text = intervalTextBox.Text;
            try
            {
                int value = int.Parse(text);
                if (value <= 0)
                    throw new FormatException();
                Interval = value;
            }
            catch (FormatException)
            {
                MessageBox.Show("Erreur : \"" + text + "\" n'est pas un nombre entier supérieur ou égale à zéro.");
            }
            Message = messageTextBox.Text;
            if (threadRadioButton.Checked)
                Mode = ChatMsgGenerator.GeneratorType.Thread;
            else
                Mode = ChatMsgGenerator.GeneratorType.Timer;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void defaultButton_Click(object sender, EventArgs e)
        {
            intervalTextBox.Text = DefaultInterval.ToString();
            messageTextBox.Text = DefaultMessage;
            if (DefaultMode == ChatMsgGenerator.GeneratorType.Thread)
                threadRadioButton.Checked = true;
            else
                timerRadioButton.Checked = true;
        }


    }
}
